package com.microcdyUser.controller;
import com.microcdy.sys.pojo.SysUserOnline;
import com.microcdyUser.service.SysUserOnlineService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/****
 * @Author:cdy
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/sysUserOnline")
@CrossOrigin
public class SysUserOnlineController {

    @Autowired
    private SysUserOnlineService sysUserOnlineService;

    /***
     * SysUserOnline分页条件搜索实现
     * @param sysUserOnline
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  SysUserOnline sysUserOnline, @PathVariable  int page, @PathVariable  int size){
        //调用SysUserOnlineService实现分页条件查询SysUserOnline
        PageInfo<SysUserOnline> pageInfo = sysUserOnlineService.findPage(sysUserOnline, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SysUserOnline分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SysUserOnlineService实现分页查询SysUserOnline
        PageInfo<SysUserOnline> pageInfo = sysUserOnlineService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sysUserOnline
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<SysUserOnline>> findList(@RequestBody(required = false)  SysUserOnline sysUserOnline){
        //调用SysUserOnlineService实现条件查询SysUserOnline
        List<SysUserOnline> list = sysUserOnlineService.findList(sysUserOnline);
        return new Result<List<SysUserOnline>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable String id){
        //调用SysUserOnlineService实现根据主键删除
        sysUserOnlineService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SysUserOnline数据
     * @param sysUserOnline
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  SysUserOnline sysUserOnline,@PathVariable String id){
        //设置主键值
        sysUserOnline.setSessionId(id);
        //调用SysUserOnlineService实现修改SysUserOnline
        sysUserOnlineService.update(sysUserOnline);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SysUserOnline数据
     * @param sysUserOnline
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   SysUserOnline sysUserOnline){
        //调用SysUserOnlineService实现添加SysUserOnline
        sysUserOnlineService.add(sysUserOnline);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SysUserOnline数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SysUserOnline> findById(@PathVariable String id){
        //调用SysUserOnlineService实现根据主键查询SysUserOnline
        SysUserOnline sysUserOnline = sysUserOnlineService.findById(id);
        return new Result<SysUserOnline>(true,StatusCode.OK,"查询成功",sysUserOnline);
    }

    /***
     * 查询SysUserOnline全部数据
     * @return
     */
    @GetMapping
    public Result<List<SysUserOnline>> findAll(){
        //调用SysUserOnlineService实现查询所有SysUserOnline
        List<SysUserOnline> list = sysUserOnlineService.findAll();
        return new Result<List<SysUserOnline>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
